<?php
$sd = '';
$xd = '';
$height = '';
if(!empty($_POST)){

$sd = !empty($_POST['sd']) ? floatval($_POST['sd']) : 0 ;
$xd = !empty($_POST['xd']) ? floatval($_POST['xd']) : 0 ;
$height = !empty($_POST['height']) ? floatval($_POST['height']) : 0 ;

$mj = 1/2 * ( $sd + $xd ) * $height;


}

?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="textml; charset=GB2312" />
<title>计算梯形</title>
</head>

<body>
<form action="" method="POST">
<h3>计算梯形面积</h3>
<p>上底：<input type="text" name="sd" id="sd" value="<?php echo $sd; ?>" /></p>
<p>下底：<input type="text" name="xd" id="xd" value="<?php echo $xd; ?>" /></p>
<p>高：<input type="text" name="height" id="height" value="<?php echo $height; ?>" /></p>
<?php if(!empty($_POST)){ ?>
<p>面积：<?php echo $mj; ?> </p>
<?php } ?>
<p><input type="submit" name="smt" value="计算" /></p>

</form>
</body>
